package interviewClassic150;

import org.junit.Test;

public class RemoveDuplicates {
    public int removeDuplicates(int[] nums) {
        if (nums.length == 0) return 0;

        if (nums.length == 1) return 1;

        int n = nums.length;

        int insertIndex = 0;
        for (int i = 1; i < n; i++) {
            if (nums[i] != nums[i - 1]) nums[insertIndex++] = nums[i - 1];
        }

        //最后一个有序元素处理
        nums[insertIndex++] = nums[n - 1];

        return insertIndex;
    }

    @Test
    public void test() {
        int[] nums = {0,0,1,1,1,2,2,3,3,4};
        int k = removeDuplicates(nums);
        System.out.println(k);
    }
}
